package com.zhentao.controller;

import com.zhentao.model.banner.dto.BannerDto;
import com.zhentao.model.banner.pojo.AdBanner;
import com.zhentao.model.common.dtos.ResponseResult;
import com.zhentao.service.AdBannerService;
import io.minio.errors.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.IOException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;

@RestController
@RequestMapping("api/v1/admin/banner")
@Api(tags = "BannerController-Banner管理")
public class BannerController {
    @Resource
    AdBannerService adBannerService;

    /*
     * 删除banner数据(根据id)
     * */
    @PostMapping("/del")
    @ApiOperation("删除轮播图")
    public ResponseResult del(@RequestParam("id") int id){
        return adBannerService.deleteByid(id);
    }

    /*
     * 查询所有banner数据
     * */
    @ApiOperation("查询所有banner")
    @PostMapping("/find")
    public ResponseResult findAll(@RequestBody BannerDto dto){
        return adBannerService.findAll(dto);
    }
    /*
     * 查询所有banner数据
     * */
    @ApiOperation("查询所有上架banner")
    @PostMapping("/findUpAll")
    public ResponseResult findUpAll(){
        return adBannerService.findUpAll();
    }

    /*
     * banner数据上传
     * */
    @ApiOperation("banner上传")
    @PostMapping("/upload")
    public ResponseResult uploadPicture(@RequestBody AdBanner banner) {
        return adBannerService.uploadPicture(banner);
    }

    @PostMapping("/delete")
    @ApiOperation(("banner硬删除"))
    public ResponseResult delete(@RequestParam("id") Integer id){
        adBannerService.removeById(id);
        return ResponseResult.okResult("删除成功");
    }
}
